package io.renren.modules.ProjectControl.Service;

import io.renren.modules.ProjectControl.Service.taskService.TaskServiceP1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
//?pageSize={pageSize}&pageNum={pageNum}&trayType={trayType}&componentsName={trayType}&type={trayType}
//http://localhost:8898/api/v1/device-info/list?pageSize=10&pageNum=1&requestStartDate=&requestEndDate=&deviceName=&deviceNo=&loadType=
//http://localhost:8898/api/v1/device-info/list?pageSize=10&pageNum=1&requestStartDate=20220531&requestEndDate=20220601&deviceName=&deviceNo=&loadType=
//http://localhost:8898/api/v1/device-run-data/param?deviceNo=BC-SS08120
//http://localhost:8898/api/v1/device-run-data/list?pageSize=10&pageNum=1&requestStartDate=20220607&requestEndDate=20220909&deviceStatus=&deviceNo=

@Service
@RefreshScope
public class TaskServiceP1iml implements TaskServiceP1 {
        @Autowired
        private RestTemplate restTemplate;
        @Value("${project.p1location}")
        private String P1Location;


        @Override
        public String getDeviceInfo(Map<String, Object> map) {

                return restTemplate.getForObject(P1Location+"/v1/device-info/list?pageSize={pageSize}&pageNum={pageNum}&requestStartDate={requestStartDate}&requestEndDate={requestEndDate}&deviceName={deviceName}&deviceNo={deviceNo}&loadType={loadType}",String.class,map);
        }

        @Override
        public String getDeviceRunData(Map<String, Object> map) {
                return restTemplate.getForObject(P1Location+"/v1/device-run-data/list?pageSize={pageSize}&pageNum={pageNum}&requestStartDate={requestStartDate}&requestEndDate={requestEndDate}&deviceStatus={deviceStatus}&deviceNo={deviceNo}",String.class,map);
        }

        @Override
        public String getDeviceRunParam(Map<String, Object> map) {
                return restTemplate.getForObject(P1Location+"/v1/device-run-data/param?deviceNo={deviceNo}",String.class,map);

        }

        @Override
        public String getDeviceRundetails(Map<String, Object> map) {
                return restTemplate.getForObject(P1Location+"/v1/device-run-data/details?deviceNo={deviceNo}&requestTime={requestTime}",String.class,map);

        }

        @Override
        public String getMaterialData(Map<String, Object> map) {
                System.out.println(map);
//                {pageSize=10, pageNum=1, trayType=, componentsName=, type=}
//                HashMap<String,String> params=new HashMap<>();
//                params.put("params",map.toString());
                System.out.println( map.get("pageNum"));
                System.out.println( map.get("trayType"));
                return restTemplate.getForObject(P1Location+"/v1/material-data/list?pageSize={pageSize}&pageNum={pageNum}&trayType={trayType}&componentsName={componentsName}&type={Type}",String.class,map);

        }

        @Override
        public String getStaffInfo(Map<String, Object> map) {
                return restTemplate.getForObject(P1Location+"/v1/staff-info/list?pageSize={pageSize}&pageNum={pageNum}&name={name}&no={no}",String.class,map);

        }
}